package com.nariano.server.utils.aop.rwsemaphore;

import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;


import org.hibernate.event.LockEvent;



public class Semaphore {
	
	ReentrantReadWriteLock lock  = new ReentrantReadWriteLock();
	
	private static Logger logger = Logger.getLogger(Semaphore.class.getCanonicalName());

	public void acquireRead() {
		lock.readLock().lock();
	}

	public void releaseRead() {
		lock.readLock().unlock();
	}

	public void acquireWrite() {
		lock.writeLock().lock();
	}

	

	public void releaseWrite() {
		lock.writeLock().unlock();
	}

	@Override
	public String toString() {
		return String.format("state: %s", lock.isWriteLocked()?"write":"read");
	}
	
	
}

